package com.zcx.model;

import com.alibaba.fastjson.JSON;
import com.zcx.R;
import com.zcx.base.BaseModel;
import com.zcx.bean.PayBean;
import com.zcx.bean.WxPayBean;
import com.zcx.net.OkHttpHelp;
import com.zcx.net.UrlHelper;
import com.zcx.util.GsonResultUtils;
import com.zcx.util.LogUtil;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Response;

/**
 * @author：zcx
 * @date:on 2018/3/6 0006 18:21
 */

public class PayModel implements BaseModel {
    @Override
    public void alipayData(final aliypayOnListener listener) {
        listener.onstart(R.string.please_wait);
        Map<String, String> nameMap = new HashMap<>();
        nameMap.put("userId", "43bdeef3e5524849a089f7d86f4a180b");
        nameMap.put("orderId", "6316f1fe01474d38878b2e9fb09d76b9");
//        OkHttpHelp.postOkUserHttp(UrlHelper.UNIFIED_ORDER, JSON.toJSONString(nameMap),new BaseCallback(new BaseCallback.BaseInterface() {
//            @Override
//            public void onError(int error, String message) {
//                listener.onFail("支付出错");
//            }
//
//            @Override
//            public void onSuccess(BaseBean baseBean) {
//                PayBean payBean = JSON.parseObject(baseBean.getData(), PayBean.class);
//                listener.onSucc(payBean);
//            }
//        }));
        OkHttpHelp.sendOkHttpGetRequest(UrlHelper.UNIFIED_ORDER+"47668a5cbd9848bf8d179365b449cece",new okhttp3.Callback(){
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onFail("支付出错");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                PayBean payBean = GsonResultUtils.getResultData(response.body().string(),PayBean.class);
                listener.onSucc(payBean);
            }
        });
    }

    @Override
    public void wxPayData(final wxPayOnListener listener) {
        listener.onstart(R.string.please_wait);
        OkHttpHelp.sendOkHttpPostRequest(UrlHelper.UNIFIED_ORDER,new okhttp3.Callback(){
            @Override
            public void onFailure(Call call, IOException e) {
                listener.onFail("支付出错");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                WxPayBean payBean = GsonResultUtils.getResultData(response.body().string(),WxPayBean.class);
                LogUtil.d("aaaa",payBean.getAppid());
                listener.onSucc(payBean);
            }
        });
    }
}
